﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.Sql;
using BookStore.Solution.Configurations;

namespace BookStore.Solution.Presentation
{
    public partial class frmSetUp : DevComponents.DotNetBar.OfficeForm
    {
        public frmSetUp()
        {
            InitializeComponent();
            txtImageFolderPath.Text = Configs.ImageFolderPath;
            txtServer.Text = Configs.ConnectionString;
        }
        public static List<string> GetNetworkInstances()
        {
            var rel = new List<string>();
            var dt = SqlDataSourceEnumerator.Instance.GetDataSources();
            for (var i = 0; i < dt.Rows.Count; i++)
            {
                var row = dt.Rows[i];
                var name = row["ServerName"].ToString();
                var ins = row["InstanceName"] == null ? "" : "\\" + row["InstanceName"];
                rel.Add(name + ins);
            }
            return rel;
        }

        private void btnImageFolderPath_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                Configs.EditAppSetting("ImageFolderPath", folderBrowserDialog.SelectedPath);
                txtImageFolderPath.Text = folderBrowserDialog.SelectedPath;
                MessageBox.Show("Yêu cầu khởi động lại chương trình!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                
                Application.Restart();
            }
        }

        private void btnChooseServer_Click(object sender, EventArgs e)
        {
            frmChooseServer frm = new frmChooseServer();
            frm.ShowDialog();
        }

        private void frmSetUp_Load(object sender, EventArgs e)
        {

        }
        
    }
}